package com.example.gisapplication;

import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.DrawStatus;
import com.esri.arcgisruntime.mapping.view.DrawStatusChangedEvent;
import com.esri.arcgisruntime.mapping.view.DrawStatusChangedListener;
import com.esri.arcgisruntime.mapping.view.MapView;

//加载基础底图
public class LayersActivity extends AppCompatActivity implements View.OnClickListener {
    MapView mapView;
    ArcGISMap mArcGISMap;
    DrawerLayout drawerLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layers);
        drawerLayout = findViewById(R.id.drawerLayout);
        findViewById(R.id.tv1).setOnClickListener(this);
        findViewById(R.id.tv2).setOnClickListener(this);
        findViewById(R.id.tv3).setOnClickListener(this);
        findViewById(R.id.tv4).setOnClickListener(this);
        findViewById(R.id.tv5).setOnClickListener(this);
        findViewById(R.id.tv6).setOnClickListener(this);


        mapView = findViewById(R.id.mapView);

        mArcGISMap = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 47.6047381, -122.3334255, 12);

        mapView.setMap(mArcGISMap);


        //监听图层的视图状态
        mapView.addDrawStatusChangedListener(new DrawStatusChangedListener() {
            @Override
            public void drawStatusChanged(DrawStatusChangedEvent drawStatusChangedEvent) {
                Log.d("drawStatusChanged", "drawStatusChangedEvent.getDrawStatus: " + drawStatusChangedEvent.getDrawStatus());
            }
        });

//        动态地图图层

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv1:
                mArcGISMap.setBasemap(Basemap.createStreets());
                break;
            case R.id.tv2:
                mArcGISMap.setBasemap(Basemap.createNavigationVector());
                break;
            case R.id.tv3:
                mArcGISMap.setBasemap(Basemap.createTopographic());
                break;
            case R.id.tv4:
                mArcGISMap.setBasemap(Basemap.createTopographicVector());
                break;
            case R.id.tv5:
                mArcGISMap.setBasemap(Basemap.createLightGrayCanvas());
                break;
            case R.id.tv6:
                mArcGISMap.setBasemap(Basemap.createLightGrayCanvasVector());
                break;
        }
        Toast.makeText(v.getContext(), "xxx", Toast.LENGTH_SHORT).show();
        drawerLayout.closeDrawer(Gravity.LEFT);
    }


    @Override
    protected void onPause() {
        mapView.pause();
        super.onPause();
    }

    @Override
    protected void onResume() {
        mapView.resume();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        mapView.dispose();
        super.onDestroy();
    }

}